package com.ktjiaoyu.crm.connller;

import com.ktjiaoyu.crm.entity.User;
import jdk.internal.org.objectweb.asm.tree.analysis.Value;
import org.hibernate.annotations.NamedQueries;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import java.util.List;


public interface UserRepository extends JpaRepository<User,Long> , JpaSpecificationExecutor<User> {

    public Page<User> findPageByUsrRoleId(Long roleId, Pageable pageable);
    //查询
    //根据用户名查询用户
    public List<User> findByUsrName(String usrName);

    //修改删除统计
    public Long UsrName(String usrName);

    public List<User> findByUsrNameLike(String usrName);

@Query("select u from User u where u.usrRoleId=?1")
    public List<User> findByRoleIdss(Long roleId);

@Query(value ="select * from sys_user where usr_role_id=?1",nativeQuery = true)
    public List<User> findByRoleIds(Long roleId);

@Query("select u from User u where u.usrRoleId=:roleId")
    public List<User> findByRoleId(@Param("roleId") Long roleId);



@Transactional(timeout = 10)
    @Modifying
    @Query("update  User u set u.usrName=?1 where u.usrId=?2" )
    public int modifyNameById(String usrName,Long usrId);

}
